package main.scripts;

import javax.smartcardio.ATR;
import javax.swing.JOptionPane;

import com.sun.org.apache.bcel.internal.generic.StoreInstruction;

import main.bots.Script;
import main.hooks.RSObject;
import main.hooks.RSTile;
import main.listeners.ServerMessageListener;

public class MiningTest extends Script implements ServerMessageListener {

	private int xCoord = 3016;
	private int yCoord = 3367;
	private int objectId = 2091;
	private int[] pick = { 1266 };
	public RSTile bankTile = new RSTile(3028, 3379);
	public int bankId = 2213;
	public RSTile bankBooth = new RSTile(3029, 3379);
	public RSTile mainTile = new RSTile(3016, 3368);
	long lastSave = 0;

	@Override
	public boolean endCondition() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String[] getAuthors() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getCategory() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getDescription() {
	return "Just a test for mining methods";
	}

	@Override
	public String getScriptName() {
		return "Mining Test";
	}

	@Override
	public double getVersion() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int loop() {
		if(lastSave == 0)
			lastSave = System.currentTimeMillis();
		
		if(System.currentTimeMillis() - lastSave > 60000) {
			sendCommand("save");
			lastSave = System.currentTimeMillis();
		}
		if(isInventoryFull()) {
			if(getMyLocation().getX() == bankTile.getX() && getMyLocation().getY() == bankTile.getY()) {
				openBank(bankBooth, 2213);
				wait(random(2000, 5000));
				bank.depositAll();
				return 1000;
			} else {
				walkTo(bankTile);
				return 4000;
			}
		} else {
			
		
		if(getAnimation() != -1) {
			debug("Mining");
			return 1000;
		}
		if(getMyLocation().getX() != 3016 || getMyLocation().getY() != 3368) {
			walkTo(mainTile);
			debug("Walking to main tile");
			return 3000;
		}
		debug("doing atobject");
		atObject132(objectId, xCoord, yCoord);
		
	}
		return 4000;
	}
	@Override
	public void onFinish() {
		// TODO Auto-generated method stub

	}

	@SuppressWarnings("deprecation")
	@Override
	public boolean onStart() {
		return getMyClient() != null;
	}

	@Override
	public void serverMessageRecieved(String message) {
		// TODO Auto-generated method stub
		
	}

}
